<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('代码生成')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form search-form" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">连接名称</label>
                    <div class="layui-input-inline">
                        <input autocomplete="off" lay-affix="clear" class="layui-input" name="tableName" placeholder="" type="text">
                    </div>
                </div>
                <div class="layui-inline mt5">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline input-sm">
                        <input class="layui-input" id="startTime" name="params[beginTime]" placeholder="开始时间" type="text"/>
                    </div>
                    <span class="layui-form-mid">-</span>
                    <div class="layui-input-inline input-sm">
                        <input class="layui-input" id="endTime" name="params[endTime]" placeholder="结束时间" type="text"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" data-type="reload" id="form-search" lay-filter="form-search"
                            lay-submit type="button"><i class="layui-icon">&#xe615;</i>搜索
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">

        <div class="layui-row">
            <div class="layui-col-xs2 layui-form">
                <div id="fast_list" class="fast_list"></div>
            </div>
            <div class="layui-col-xs2 layui-form">
                <div id="fast_list_db" class="fast_list"></div>
            </div>
            <div class="layui-col-xs8">


            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script>
    let prefix = "/generate";
    layui.use(['common', 'layer', 'form','tab', 'laydate', 'table', 'jquery','util','list','dropdown'], function () {
        let $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            common = layui.common,
            laydate = layui.laydate,
            pearTab = layui.tab,
            util = layui.util,
            list = layui.list,
            table = layui.table;
        let dropdown = layui.dropdown;

        let current = {}
        let id = 0;

        // 渲染连接记录
        let _list = list.render({
            elem:"fast_list",
            title:"connectName",
            url:"/conn/connList",
        })

        // 回调 第一个参数为当前点击的JQ对象  第二个参数为当前点击返回的数据
        _list.click(function (param,data) {
            console.log(data)
            data.password = data.userPwd
            id = data.id
            table.reloadData('table_gen', {
                where: {id:id}, // 数据异步请求时携带的字段集 --- 属性设置有效，因属于数据相关属性
                method: 'post',
                scrollPos: true,
                height: 2000 // 高度  --- 属性设置无效，因不属于数据相关属性
            })
        })



        let active = {
            reload: function () {
                search(false);
            },
            remove: function (ids) {
                active['reload'].call(this);
            }
        };

        let insStart = laydate.render({
            elem: '#startTime',
            min: 0,
            done: function (value, date) {
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                insEnd.config.elem[0].focus();
            }
        });

        let insEnd = laydate.render({
            elem: '#endTime',
            min: 0,
            done: function (value, date) {
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        form.on('submit(form-search)', function (data) {
            search(true);
        });


        form.on('select(databases)', function (data){
            const value = data.value;
            console.log(value)
            if (!value){
                return
            }
            table.reloadData('table_gen', {
                where: {tableName:value}, // 数据异步请求时携带的字段集 --- 属性设置有效，因属于数据相关属性
                scrollPos: true,
                height: 2000 // 高度  --- 属性设置无效，因不属于数据相关属性
            })
        })
    });

    function search(isResetCurr) {
        let field = JSON.stringify($('#searchForm'));
        let options = {
            where: field
        };
        if (isResetCurr === true) {
            options.page = {
                curr: 1
            };
        }
    }
</script>
</body>
</html>
